/**
 * @package: BrickCAD
 * @className: TopView.java
 * @package: default
 * @author: Sean O'Brien, Jack, Lester Tam, Erik Telstad
 * @date_created: November 16, 2009
 * @last_motified: November 16, 2009
 * 
 * 
 * 
 */

import java.awt.BorderLayout;
import java.util.Observable;


public class TopView extends BrickView {

	private static final long serialVersionUID = 1L;
	private static String title = "Top View";
	static int openFrameCount = 0;
	static final int xOffset = 90, yOffset = 5;
	
	private BrickImagePanel topImage;

	/**
	 * @param theModel
	 */
	public TopView(Brick theModel) {
		super(theModel);
		setTitle(title);
		openFrameCount++;
		setSize(300, 300);
		this.setLocation(xOffset*openFrameCount, yOffset*openFrameCount);

		double x =(getX() + (getWidth()/2.0)) - model.getLength()/2.0;
		double y =(getY() + (getHeight()/2.0)) - model.getWidth()/2.0;
		topImage = new BrickImagePanel(x, y, model.getLength(), model.getWidth());
		getContentPane().add(topImage, BorderLayout.CENTER);
		
		add(topImage);
	}
	

	/* (non-Javadoc)
	 * @see BrickView#update(java.util.Observable, java.lang.Object)
	 */
	@Override
	public void update(Observable arg0, Object o) {
		System.out.println("Updating TopView #" + openFrameCount);
		model = (Brick) arg0;
		if(topImage.getWidth() != model.getLength()) {
			System.out.print("Brick length: " + model.getLength());
			topImage.setBrickWidth(model.getLength());
		}
		if(topImage.getHeight() != model.getWidth()) {
			System.out.print("Brick height: " + model.getWidth());
			topImage.setBrickHeight(model.getWidth());
		}
		System.out.println();
		topImage.repaint();
	}
}
